package com.hzhc.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzhc.entity.ChargeContractDetail;
import com.hzhc.mapper.ChargeContractDetailMapper;
import com.hzhc.service.ChargeContractDetailService;
import com.hzhc.utils.ResultUtil;
import com.hzhc.vo.ChargeContractDetailVo;
import lombok.RequiredArgsConstructor;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 计费合同子表 服务实现类
 * </p>
 *
 * @author 1
 * @since 2024-05-28
 */
@Service
@RequiredArgsConstructor
public class ChargeContractDetailServiceImpl extends ServiceImpl<ChargeContractDetailMapper, ChargeContractDetail> implements ChargeContractDetailService {

    @Override
    public List<ChargeContractDetailVo> getContractDetailList(Page<ChargeContractDetailVo> page, ChargeContractDetailVo vo) {
        IPage<ChargeContractDetailVo> iPage = baseMapper.getContractDetailList(page,vo);
        return iPage.getRecords();
    }

    @Override
    public ResultUtil<T> addContractDetail(ChargeContractDetail detail) {
        if(save(detail)){
            return ResultUtil.ok();
        }
        return ResultUtil.fail();
    }

    @Override
    public ResultUtil<T> updateContractDetail(ChargeContractDetail detail) {
        if (updateById(detail)){
            return ResultUtil.ok();
        }
        return ResultUtil.fail();
    }

    @Override
    public ResultUtil<T> delContractDetail(Long id) {
        ChargeContractDetail detail = getById(id);
        detail.setDisable(true);
        if (updateById(detail)){
            return ResultUtil.ok();
        }
        return ResultUtil.fail();

    }

}
